package com.isoft.airportsystem.service.impl.Flight;

import com.isoft.airportsystem.entity.flight.Aircraft;
import com.isoft.airportsystem.mapper.Flight.AircraftMapper;
import com.isoft.airportsystem.service.flight.AircraftService;
import com.isoft.airportsystem.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AircraftServiceImpl implements AircraftService {

    @Autowired
    private AircraftMapper aircraftMapper;

    @Override
    public List<Aircraft> getAllAircrafts() {
        return aircraftMapper.selectAllAircrafts();
    }

    @Override
    public Aircraft getByCode(String aircraftCode) {
        return aircraftMapper.selectByCode(aircraftCode);
    }

    @Override
    public List<Aircraft> queryAircrafts(Aircraft aircraft) {
        return aircraftMapper.selectAircraftsByCondition(aircraft);
    }

    @Override
    public PageResult<Aircraft> queryAircraftPage(int pageNum, int pageSize, Aircraft aircraft) {
        int offset = (pageNum - 1) * pageSize;
        List<Aircraft> list = aircraftMapper.selectAircraftPage(offset, pageSize, aircraft);
        int total = aircraftMapper.countAircrafts(aircraft);
        return new PageResult<>(total, list);
    }
}
